Skip to content

Handle ListedColormaps in expand and cmap_and_norm - #241

Merged
JamesVarndell merged 2 commits into
ecmwf:developfrom
burggraaff:develop
Aug 4, 2026
Merged

Handle ListedColormaps in expand and cmap_and_norm#241
JamesVarndell merged 2 commits into
ecmwf:developfrom
burggraaff:develop

Conversation

@burggraaff

Copy link
Copy Markdown
Contributor

Description

Resolves #240 by checking whether colors is a ListedColormap directly upon entering cmap_and_norm rather than after modification (extension). Now works when defining the Style as follows, where levels represents the right border of each level and there is an additional extension at the end. I'm assuming that's the intended behaviour but not sure.

newstyle = Style(
    colors=ListedColormap(['#ff0100', '#feaa00', '#fffc03', '#ffffff', '#ffffff', '#eaccf8', '#af51c3', '#7a007b']),
    levels=[-2, -1.5, -1, 0, 1, 1.5, 2],
    extend="both",
)

# Plot with custom style:
fig = ekp.Figure(rows=1, columns=1)
subplot = fig.add_map(domain="Spain")
subplot.grid_cells(data, z="SPI1", style=newstyle)
subplot.legend()
fig.coastlines()
fig.show()
download

Testing without style= shows no change in the default behaviour (as intended) but I'm not sure what other tests are useful here.

Minimum working example, can probably be improved in terms of e.g. skipping parts of cmap_and_norm completely for ListedColormaps.

I think it would be good to add this to the documentation gallery somewhere but wasn't sure where. If you want to go really crazy you could add SPI and SPEI as built-in styles.

Contributor Declaration

By opening this pull request, I affirm the following:

  • All authors agree to the Contributor License Agreement.
  • The code follows the project's coding standards.
  • I have performed self-review and added comments where needed.
  • I have added or updated tests to verify that my changes are effective and functional.
  • I have run all existing tests and confirmed they pass.

@JamesVarndell
JamesVarndell merged commit b70aed4 into ecmwf:develop Aug 4, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specification of colours in ListedColormap + BoundaryNorm

3 participants